/**
 * 
 */
package cn.ac.istic.lkt.atv;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

/**
 * @author scd
 *
 */
public class SentenceTree {
	private String sents; //sentences
	private String treesents; // bracketted trees
	private ParseTree trees; //structured trees
	
	public SentenceTree(String ts){
		treesents = ts;		
	}
	
	public void parse(){
		this.trees = new ParseTree(treesents);
		sents = trees.getSent();
	}
	
	public static List<SentenceTree> parseFile(File f){
		List<SentenceTree> stlist = new ArrayList<SentenceTree>();
		InputStream in = null;
		try {
			in = new FileInputStream(f);
		    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
		    String line = null;
		    while ((line = reader.readLine()) != null) {
		    	if(line.trim().length()==0){
		    		continue;
		    	}
		        SentenceTree st = new SentenceTree(line.trim());
		        st.parse();
		        stlist.add(st);
		    }
		    return stlist;
		} catch (IOException x) {
		    System.err.println(x);
		    return null;
		} //finally {
		   // if (in != null) in.close();
		//}
	}
	
	public String getSents() {
		//System.err.println(sents);
		return sents;
	}
	public String getShortSents(){
		int count = 0;
		for(int i=0;i<sents.length();i++){			
			if(sents.charAt(i) ==' ') count++;
			if(count >= 10){
				//System.err.println(sents.substring(0,i));
				return sents.substring(0,i)+" ...";
			}
		}
		return sents;
	}
	public void setSents(String sents) {
		this.sents = sents;
	}
	public String getTreesents() {
		return treesents;
	}
	public void setTreesents(String treesents) {
		this.treesents = treesents;
	}
	
	public ParseTree getTrees() {
		return trees;
	}
	public void setTrees(ParseTree trees) {
		this.trees = trees;
	}
	

}
